home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / VSTNUTE.C < prev    next >
C/C++ Source or Header  |  1995-01-23  |  17KB  |  471 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81.  /* FOLLOWING ADAPTED FROM Sattrack (the Unix Version by Dr. M. Bester) */
  82.  
  83. #include <windows.h>
  84. #include <math.h>
  85. #include <stdlib.h>
  86.  
  87. #include "vstdefs.h"
  88. #include "constant.h"
  89. #include "vsttype.h"
  90. #include "vstextrn.h"
  91.  
  92. /*
  93.  * eqxnutation: finds nutation in longitude and obliquity, and the equation
  94.  *           of the equinoxes.
  95.  */
  96.  
  97. double
  98. eqxnutation(tp)
  99. track_t *tp;
  100. {
  101.     double tu, tusq, tucb, eps, l, lp, f, d, o;
  102.     double totPsi, totEps;
  103.     extern void nuteseries(double, double, double, double, double,
  104.         double, double *, double *);
  105.  
  106.     tu   = (tp->juliandate - JULDAT2000) / JULCENT;
  107.     tusq = tu*tu;
  108.     tucb = tusq*tu;
  109.     /*
  110.      * calculate the mean obliquity of the ecliptic (eps), based on the
  111.      * epoch J2000.0
  112.      *
  113.      * For reference see the "Astronomical Almanac", 1986, pages B24 - B31.
  114.      * The equation for calculation of eps has been taken from the
  115.      * "Astronomical Almanac", 1984, page S21 (in the Supplement section)
  116.      */
  117.      
  118.     eps = (84381.448 - 46.815*tu - 0.00059*tusq + 0.001813*tucb) * CASR;
  119.  
  120.     /*
  121.      * compute the nutation in longitude (totPsi) and in obliquity (totEps)
  122.      * thus giving the true obliquity of the ecliptic (trueEps) and from
  123.      * that, the equation of the equinoxes, also based on the epoch J2000.0.
  124.      *
  125.      * Calculation of the nutation parameters totPsi and totEps is performed
  126.      * by using the "1980 IAU Theory of Nutation" (see "Astronomical
  127.      * Almanac", 1984, pp. S21-S26)
  128.      *
  129.      * Fundamental arguments of the Sun and the Moon are : l, lp, f, d, o
  130.      * (time-dependent arguments) from the "Astronomical Almanac", 1984,
  131.      * p. S26. The function reduce() reduces their values into the interval
  132.      * (0, 2pi). The nutation in longitude (totPsi) and in obliquity (totEps)
  133.      * are updated when the update time interval is elapsed.
  134.      */
  135.      
  136.     l   = reduce ( (485866.733 + 1717915922.633 * tu + 31.310 * tusq +
  137.           0.064 * tucb) * CASR, ZERO, TWOPI);
  138.  
  139.     lp  = reduce ( (1287099.804 +  129596581.224 * tu - 0.577 *  tusq -
  140.           0.012 * tucb) * CASR, ZERO, TWOPI);
  141.  
  142.     f   = reduce ( (335778.877 + 1739527263.137 * tu -13.257 * tusq +
  143.           0.011 * tucb) * CASR, ZERO, TWOPI);
  144.  
  145.     d   = reduce ( (1072261.307 + 1602961601.328 * tu - 6.891 * tusq +
  146.           0.019 * tucb) * CASR, ZERO, TWOPI);
  147.  
  148.     o   = reduce ( (450160.280 - 6962890.539 * tu + 7.455 * tusq +
  149.           0.008*tucb) * CASR, ZERO, TWOPI);
  150.  
  151.     nuteseries(tu, l, lp, f, d, o, &totPsi, &totEps);
  152.  
  153.     return totPsi * cos(eps + totEps);                     /* [rad] */
  154. }
  155.  
  156. /*
  157.  *  nuteseries: calculates sine and cosine series of nutation
  158.  */
  159.  
  160. static void
  161. nuteseries(tu,l,lp,f,d,o, Psip, Epsp)
  162. double tu, l, lp, f, d, o;
  163. double *Psip, *Epsp;
  164. {
  165.     /* BEWARE STACK OVERFLOW */
  166.     double b[106], sinb[106], c[106], cosc[106], bc[106];
  167.     double sip, psp;
  168.     int n;
  169.  
  170.     /*
  171.      * Coefficients and arguments of the sine and cosine terms for the
  172.      * Fourier Series representation (106 terms) of the nutation in longitude
  173.      * (sine) and of the nutation in obliquity (cosine), respectively.
  174.      * All known long and short-term variations are included.
  175.      *
  176.      * totEps  = b(0)*cos(B(0)) + b(1)*cos(B(1)) + ... + b(105)*cos(B(105))
  177.      *
  178.      * with b(n) = aat(n,0) + aat(n,1)*tu  for n = [0..14]   (time-dependent)
  179.      * and  B(n) = at(n,0)*l + at(n,1)*lp + at(n,2)*f + at(n,3)*d + at(n,4)*o
  180.      *
  181.      * totPsi    = c(0)*sin(C(0)) + c(1)*sin(C(1)) + ... + c(105)*sin(C(105))
  182.      *
  183.      * with c(n) = aat(n,1) + aat(n,2)*tu  for n = [0..14]  (time-dependent)
  184.      * and  c(n) = aa(n,1)              for n = [15..105] (time-independent)
  185.      * and  C(n) = B(n)
  186.      *
  187.      *
  188.      * First: 15 terms with time-dependent arguments (either nutation in
  189.      * longitude or in obliquity is time-dependent.)
  190.      *
  191.      * The data field at[][] contains the code for the linear combinations
  192.      * of the arguments of Sun and Moon (l, lp, f, d, o)
  193.      */
  194.      
  195.     static double at[15][5] = {
  196.          {  0,  0,  0,  0,  1},
  197.          {  0,  0,  0,  0,  2},
  198.          {  0,  0,  2, -2,  2},
  199.          {  0,  1,  0,  0,  0},
  200.          {  0,  1,  2, -2,  2},
  201.          {  0, -1,  2, -2,  2},
  202.          {  0,  0,  2, -2,  1},
  203.          {  0,  2,  0,  0,  0},
  204.          {  0,  2,  2, -2,  2},
  205.          {  0,  0,  2,  0,  2},
  206.          {  1,  0,  0,  0,  0},
  207.          {  0,  0,  2,  0,  1},
  208.          {  1,  0,  2,  0,  2},
  209.          {  1,  0,  0,  0,  1},
  210.          { -1,  0,  0,  0,  1}
  211.     };
  212.  
  213.     static double aat[15][4] = {
  214.          { -171996,  -174.2,   92025,     8.9},
  215.          {    2062,     0.2,    -895,     0.5},
  216.          {  -13187,    -1.6,    5736,    -3.1},
  217.          {    1426,    -3.4,      54,    -0.1},
  218.          {    -517,     1.2,     224,    -0.6},
  219.          {     217,    -0.5,     -95,     0.3},
  220.          {     129,     0.1,     -70,     0.0},
  221.          {      17,    -0.1,       0,     0.0},
  222.          {     -16,     0.1,       7,     0.0},
  223.          {   -2274,    -0.2,     977,    -0.5},
  224.          {     712,     0.1,      -7,     0.0},
  225.          {    -386,    -0.4,     200,     0.0},
  226.          {    -301,     0.0,     129,    -0.1},
  227.          {      63,     0.1,     -33,     0.0},
  228.          {     -58,    -0.1,      32,     0.0}
  229.     };
  230.  
  231.     /*
  232.      * Second : 91 terms with non-time dependent arguments
  233.      */
  234.      
  235.     static double a[91][5] = {
  236.          { -2,  0,  2,  0,  1},
  237.          {  2,  0, -2,  0,  0},
  238.          { -2,  0,  2,  0,  2},
  239.          {  1, -1,  0, -1,  0},
  240.          {  0, -2,  2, -2,  1},
  241.          {  2,  0, -2,  0,  1},
  242.          {  2,  0,  0, -2,  0},
  243.          {  0,  0,  2, -2,  0},
  244.          {  0,  1,  0,  0,  1},
  245.          {  0, -1,  0,  0,  1},
  246.          { -2,  0,  0,  2,  1},
  247.          {  0, -1,  2, -2,  1},
  248.          {  2,  0,  0, -2,  1},
  249.          {  0,  1,  2, -2,  1},
  250.          {  1,  0,  0, -1,  0},
  251.          {  2,  1,  0, -2,  0},
  252.          {  0,  0, -2,  2,  1},
  253.          {  0,  1, -2,  2,  0},
  254.          {  0,  1,  0,  0,  2},
  255.          { -1,  0,  0,  1,  1},
  256.          {  0,  1,  2, -2,  0},
  257.          {  1,  0,  0, -2,  0},
  258.          { -1,  0,  2,  0,  2},
  259.          {  0,  0,  0,  2,  0},
  260.          { -1,  0,  2,  2,  2},
  261.          {  1,  0,  2,  0,  1},
  262.          {  0,  0,  2,  2,  2},
  263.          {  2,  0,  0,  0,  0},
  264.          {  1,  0,  2, -2,  2},
  265.          {  2,  0,  2,  0,  2},
  266.          {  0,  0,  2,  0,  0},
  267.          { -1,  0,  2,  0,  1},
  268.          { -1,  0,  0,  2,  1},
  269.          {  1,  0,  0, -2,  1},
  270.          { -1,  0,  2,  2,  1},
  271.          {  1,  1,  0, -2,  0},
  272.          {  0,  1,  2,  0,  2},
  273.          {  0, -1,  2,  0,  2},
  274.          {  1,  0,  2,  2,  2},
  275.          {  1,  0,  0,  2,  0},
  276.          {  2,  0,  2, -2,  2},
  277.          {  0,  0,  0,  2,  1},
  278.          {  0,  0,  2,  2,  1},
  279.          {  1,  0,  2, -2,  1},
  280.          {  0,  0,  0, -2,  1},
  281.          {  1, -1,  0,  0,  0},
  282.          {  2,  0,  2,  0,  1},
  283.          {  0,  1,  0, -2,  0},
  284.          {  1,  0, -2,  0,  0},
  285.          {  0,  0,  0,  1,  0},
  286.          {  1,  1,  0,  0,  0},
  287.          {  1,  0,  2,  0,  0},
  288.          {  1, -1,  2,  0,  2},
  289.          { -1, -1,  2,  2,  2},
  290.          { -2,  0,  0,  0,  1},
  291.          {  3,  0,  2,  0,  2},
  292.          {  0, -1,  2,  2,  2},
  293.          {  1,  1,  2,  0,  2},
  294.          { -1,  0,  2, -2,  1},
  295.          {  2,  0,  0,  0,  1},
  296.          {  1,  0,  0,  0,  2},
  297.          {  3,  0,  0,  0,  0},
  298.          {  0,  0,  2,  1,  2},
  299.          { -1,  0,  0,  0,  2},
  300.          {  1,  0,  0, -4,  0},
  301.          { -2,  0,  2,  2,  2},
  302.          { -1,  0,  2,  4,  2},
  303.          {  2,  0,  0, -4,  0},
  304.          {  1,  1,  2, -2,  2},
  305.          {  1,  0,  2,  2,  1},
  306.          { -2,  0,  2,  4,  2},
  307.          { -1,  0,  4,  0,  2},
  308.          {  1, -1,  0, -2,  0},
  309.          {  2,  0,  2, -2,  1},
  310.          {  2,  0,  2,  2,  2},
  311.          {  1,  0,  0,  2,  1},
  312.          {  0,  0,  4, -2,  2},
  313.          {  3,  0,  2, -2,  2},
  314.          {  1,  0,  2, -2,  0},
  315.          {  0,  1,  2,  0,  1},
  316.          { -1, -1,  0,  2,  1},
  317.          {  0,  0, -2,  0,  1},
  318.          {  0,  0,  2, -1,  2},
  319.          {  0,  1,  0,  2,  0},
  320.          {  1,  0, -2, -2,  0},
  321.          {  0, -1,  2,  0,  1},
  322.          {  1,  1,  0, -2,  1},
  323.          {  1,  0, -2,  2,  0},
  324.          {  2,  0,  0,  2,  0},
  325.          {  0,  0,  2,  4,  2},
  326.          {  0,  1,  0,  1,  0}
  327.     };
  328.  
  329.     static double aa[91][2] = {
  330.          {   46,   -24},
  331.          {   11,     0},
  332.          {   -3,     1},
  333.          {   -3,     0},
  334.          {   -2,     1},
  335.          {    1,     0},
  336.          {   48,     1},
  337.          {  -22,     0},
  338.          {  -15,     9},
  339.          {  -12,     6},
  340.          {   -6,     3},
  341.          {   -5,     3},
  342.          {    4,    -2},
  343.          {    4,    -2},
  344.          {   -4,     0},
  345.          {    1,     0},
  346.          {    1,     0},
  347.          {   -1,     0},
  348.          {    1,     0},
  349.          {    1,     0},
  350.          {   -1,     0},
  351.          { -158,    -1},
  352.          {  123,   -53},
  353.          {   63,    -2},
  354.          {  -59,    26},
  355.          {  -51,    27},
  356.          {  -38,    16},
  357.          {   29,    -1},
  358.          {   29,   -12},
  359.          {  -31,    13},
  360.          {   26,    -1},
  361.          {   21,   -10},
  362.          {   16,    -8},
  363.          {  -13,     7},
  364.          {  -10,     5},
  365.          {   -7,     0},
  366.          {    7,    -3},
  367.          {   -7,     3},
  368.          {   -8,     3},
  369.          {    6,     0},
  370.          {    6,    -3},
  371.          {   -6,     3},
  372.          {   -7,     3},
  373.          {    6,    -3},
  374.          {   -5,     3},
  375.          {    5,     0},
  376.          {   -5,     3},
  377.          {   -4,     0},
  378.          {    4,     0},
  379.          {   -4,     0},
  380.          {   -3,     0},
  381.          {    3,     0},
  382.          {   -3,     1},
  383.          {   -3,     1},
  384.          {   -2,     1},
  385.          {   -3,     1},
  386.          {   -3,     1},
  387.          {    2,    -1},
  388.          {   -2,     1},
  389.          {    2,    -1},
  390.          {   -2,     1},
  391.          {    2,     0},
  392.          {    2,    -1},
  393.          {    1,    -1},
  394.          {   -1,     0},
  395.          {    1,    -1},
  396.          {   -2,     1},
  397.          {   -1,     0},
  398.          {    1,    -1},
  399.          {   -1,     1},
  400.          {   -1,     1},
  401.          {    1,     0},
  402.          {    1,     0},
  403.          {    1,    -1},
  404.          {   -1,     0},
  405.          {   -1,     0},
  406.          {    1,     0},
  407.          {    1,     0},
  408.          {   -1,     0},
  409.          {    1,     0},
  410.          {    1,     0},
  411.          {   -1,     0},
  412.          {   -1,     0},
  413.          {   -1,     0},
  414.          {   -1,     0},
  415.          {   -1,     0},
  416.          {   -1,     0},
  417.          {   -1,     0},
  418.          {    1,     0},
  419.          {   -1,     0},
  420.          {    1,     0}
  421.     };
  422.  
  423.     /*
  424.      * Calculate the linear combinations of the arguments of Sun and Moon
  425.      *
  426.      * B(n) = C(n) = bc(n) = ....
  427.      */
  428.      
  429.     for (n = 0; n <= 14; n++) {
  430.         bc[n] = at[n][0]*l + at[n][1]*lp + at[n][2]*f + at[n][3]*d + at[n][4]*o;
  431.         bc[n] = reduce( bc[n], ZERO, TWOPI);
  432.     }
  433.  
  434.     for (n = 15; n <= 105; n++) {
  435.         bc[n] = a[n-15][0]*l + a[n-15][1]*lp + a[n-15][2]*f
  436.                              + a[n-15][3]*d  + a[n-15][4]*o;
  437.         bc[n] = reduce( bc[n], ZERO, TWOPI);
  438.     }
  439.  
  440.     /*
  441.      * Calculate the nutation in longitude (totPsi) (sine series) and
  442.      * calculate the nutation in obliquity (totEps) (cosine series)
  443.      */
  444.      
  445.     for (n = 0; n <= 14; n++) {
  446.         b[n]    = aat[n][0] + aat[n][1]*tu;
  447.         c[n]    = aat[n][2] + aat[n][3]*tu;
  448.     }
  449.  
  450.     for (n = 15; n <= 105; n++) {
  451.         b[n]    = aa[n-15][0];
  452.         c[n]    = aa[n-15][1];
  453.     }
  454.  
  455.     for (n = 0; n <= 105; n++) {
  456.         sinb[n] = sin (bc[n]);
  457.         cosc[n] = cos (bc[n]);
  458.     }
  459.  
  460.     sip = 0.0;
  461.     psp = 0.0;
  462.  
  463.     for (n = 0; n <= 105; n++) {
  464.         sip += b[n] * sinb[n];
  465.         psp += c[n] * cosc[n];
  466.     }
  467.  
  468.     *Psip = sip * (CASR / 10000.0);                                /* [rad] */
  469.     *Epsp = psp * (CASR / 10000.0);                                /* [rad] */
  470. }
  471.